﻿function RMapmoveTool(tool){
	if(!tool){return;}
	this.tool=tool; 
	this.isLock = true;
    if(tool.src){
	    this.imgpath=this.tool.src;
	}
	
	this.toString=function(){
		return 'RMapmoveTool';
	} 
	
	this.maplet=null;
		
	this.turnon = function(){
	    this.isLock = false;
//		this.notify('onturnon');
        if(this.imgpath){
		    this.tool.src=this.imgpath;
	    }
	}
	
	this.turnoff = function(){
	    this.isLock = true;
	    if(this.imgpath){
		    this.tool.src='/img/MapmoveToolOff.gif';
	    }
//	    this.notify('onturnoff');
	}
	
	this.turnonClick = function(){
	    this.isLock = false;
		this.notify('onturnon');
        if(this.imgpath){
		    this.tool.src=this.imgpath;
	    }
	}
	
	this.tool.root=this;
	this.tool.onclick=function(){
		this.root.beginTool();
	} 
	
	this.beginTool=function(){
		if(this.begined){return;}
//		this.notify('onbegin');
		this.begined=true;
	}
	
	this.setMaplet=function(maplet){
		this.maplet=maplet;
	} 
	
	this.reset=function(){
		this.begined=false;
//		this.notify('onreset');
	}
	
	this.clear = function(){
//	    this.notify('onturnoff');
	}
	
	this.onbegin=new Array();
	this.onsuccess=new Array();
	this.onreset=new Array();
	this.onturnon=new Array();
	this.onturnoff=new Array();
	this.onclicked=new Array();
	
	this.addListener=function(listener,estring){
		switch(estring){
			case 'onbegin':
 				if(listener.onbegin){
 					this.onbegin[this.onbegin.length]=listener;
 				} else{
 					window.status=this.toString()+':不合法的'+estring+'事件对象';
 				}
			break;
			case 'onsuccess':
 				if(listener.onsuccess){
 					this.onsuccess[this.onsuccess.length]=listener;
 				} else{
 					window.status=this.toString()+':不合法的'+estring+'事件对象';
 				}
			break;
			case 'onreset':
 				if(listener.onreset){
 					this.onreset[this.onreset.length]=listener;
 				} else{
 					window.status=this.toString()+':不合法的'+estring+'事件对象';
 				}
			break;
			case 'onclicked':
 				if(listener.onclicked){
 					this.onclicked[this.onclicked.length]=listener;
 				} else{
 					window.status=this.toString()+':不合法的'+estring+'事件对象';
 				}
			break;
			case 'onturnon':
 				if(listener.onturnon){
 					this.onturnon[this.onturnon.length]=listener;
 				} else{
 					window.status=this.toString()+':不合法的'+estring+'事件对象';
 				}
			break;
			case 'onturnoff':
 				if(listener.onturnoff){
 					this.onturnoff[this.onturnoff.length]=listener;
 				} else{
 					window.status=this.toString()+':不合法的'+estring+'事件对象';
 				}
			break;
			default:
				window.status=this.toString()+'类不存在'+estring+'事件';
			break;
		}
	}
	
	this.notify=function(estring){
		switch(estring){
			case 'onbegin':
 				for(var i=0;i<this.onbegin.length;i++){
 					if(this.onbegin[i].onbegin){
 						this.onbegin[i].onbegin();
 					}else{ 
 						window.status=this.toString()+'类的某'+estring+'事件监听对象损坏';
 					}
 				}
			break;
			case 'onsuccess':
 				for(var i=0;i<this.onsuccess.length;i++){
 					if(this.onsuccess[i].onsuccess){
 						this.onsuccess[i].onsuccess();
 					}else{ 
 						window.status=this.toString()+'类的某'+estring+'事件监听对象损坏';
 					}
 				}
			break;
			case 'onreset':
 				for(var i=0;i<this.onreset.length;i++){
 					if(this.onreset[i].onreset){
 						this.onreset[i].onreset();
 					}else{ 
 						window.status=this.toString()+'类的某'+estring+'事件监听对象损坏';
 					}
 				}
			break;
			case 'onclicked':
 				for(var i=0;i<this.onclicked.length;i++){
 					if(this.onclicked[i].onclicked){
 						this.onclicked[i].onclicked();
 					}else{ 
 						window.status=this.toString()+'类的某'+estring+'事件监听对象损坏';
 					}
 				}
			break;
			case 'onturnon':
 				for(var i=0;i<this.onturnon.length;i++){
 					if(this.onturnon[i].onturnon){
 						this.onturnon[i].onturnon();
 					}else{ 
 						window.status=this.toString()+'类的某'+estring+'事件监听对象损坏';
 					}
 				}
			break;
			case 'onturnoff':
 				for(var i=0;i<this.onturnoff.length;i++){
 					if(this.onturnoff[i].onturnoff){
 						this.onturnoff[i].onturnoff();
 					}else{ 
 						window.status=this.toString()+'类的某'+estring+'事件监听对象损坏';
 					}
 				}
			break;
			default:
				window.status=this.toString()+'类不存在'+estring+'事件';
			break;
		}
	}
}